import delay from '@/utils/delay';
import Cookies from 'js-cookie';
import ins from '../axios';
// 用户操作的接口管理
export async function login(params) {
  const user = await ins.post('/passport/login', params);
  if (user) {
    // localStorage.setItem('user', JSON.stringify(user));
    Cookies.set('user', JSON.stringify(user));
  }
  return user;
}

export async function loginOut() {
  await delay(100);
  // localStorage.removeItem('user');
  Cookies.remove('user');
  return true;
}

export async function whoAmI() {
  await delay(100);
  // const user = localStorage.getItem('user');
  const user = Cookies.get('user');
  if (user) {
    return JSON.parse(user);
  }
  return null;
}
